//
//  NewsCell.m
//  student
//
//  Created by liuchen on 2018/9/6.
//  Copyright © 2018年 haiger. All rights reserved.
//

#import "NewsCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface NewsCell()
@property (nonatomic,weak) UIImageView *imgView;
@property (nonatomic,weak) UIImageView *tipsImageView;
@property (nonatomic,weak) UILabel *tLabel;
@property (nonatomic,weak) UILabel *timeLabel;
@property (nonatomic,weak) UILabel *infoLabel;
@end
@implementation NewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}


#pragma mark -
-(void)createSubView
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UIImageView *imageView = [[UIImageView alloc] init];
    [imageView setBackgroundColor:[UIColor clearColor]];
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 10.0f;
    [imageView setImage:[UIImage imageNamed:@"AppIcon"]];
    _imgView = imageView;
    [self addSubview:self.imgView];
    
    UIImageView *tipsImageView = [[UIImageView alloc] init];
    [tipsImageView setBackgroundColor:[UIColor redColor]];
    tipsImageView.layer.masksToBounds = YES;
    tipsImageView.layer.cornerRadius = 10 * SCALEUNIT;
    tipsImageView.hidden = YES;
    _tipsImageView = tipsImageView;
    [self addSubview:self.tipsImageView];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.font = [UIFont systemFontOfSize:LoginFont-1];
    _tLabel = titleLabel;
    [self addSubview:self.tLabel];
    
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.textColor = [UIColor grayColor];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.font = [UIFont systemFontOfSize:LoginFont-3];
    _timeLabel = timeLabel;
    [self addSubview:self.timeLabel];
    
    UILabel *infoLabel = [[UILabel alloc] init];
    [infoLabel setTextColor:[UIColor grayColor]];
    [infoLabel setBackgroundColor:[UIColor clearColor]];
    [infoLabel setNumberOfLines:2];
    [infoLabel setFont:[UIFont systemFontOfSize:LoginFont-3]];
    _infoLabel = infoLabel;
    [self addSubview:self.infoLabel];
    
    WS(ws);
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(ws).with.offset(30*SCALEUNIT);
        make.size.mas_equalTo(CGSizeMake(102*SCALEUNIT, 102*SCALEUNIT));
    }];
    [self.tipsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.imgView.mas_right).with.offset(-10*SCALEUNIT);
        make.top.mas_equalTo(ws.imgView.mas_top).with.offset(-10*SCALEUNIT);
        make.size.mas_equalTo(CGSizeMake(20*SCALEUNIT, 20*SCALEUNIT));
    }];
    [self.tLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.imgView.mas_right).with.offset(20*SCALEUNIT);
        make.top.mas_equalTo(ws.imgView);
        make.size.mas_equalTo(CGSizeMake(200*SCALEUNIT, 40*SCALEUNIT));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.tLabel.mas_right);
        make.top.height.mas_equalTo(ws.tLabel);
        make.right.mas_equalTo(ws).with.offset(-30*SCALEUNIT);
    }];
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.tLabel);
        make.top.mas_equalTo(ws.tLabel.mas_bottom);
        make.height.mas_equalTo(80*SCALEUNIT);
        make.right.mas_equalTo(ws.timeLabel.mas_right);
    }];
}

#pragma mark ==========填充数据==========
- (void)setNewsModels:(NewsModels *)newsModels{
    _newsModels = newsModels;
    if (_newsModels.is_read == 0) {
        self.tipsImageView.hidden = NO;
    }else {
        self.tipsImageView.hidden = YES;
    }
    //[self.imgView sd_setImageWithURL:[NSURL URLWithString:_newsModels.imgPath] placeholderImage:[UIImage imageNamed:@"TeachSeizePlaceImg"]];
    self.tLabel.text = _newsModels.messageTitle;
    self.timeLabel.text = _newsModels.sendTime;
    self.infoLabel.text = _newsModels.messageContent;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
